<?php

namespace App\Http\Controllers\Auth;

use App\Http\Model\Users;
use Illuminate\Http\Request;
use Validator;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */
	protected $redirectPath = '/admin';
	protected $loginPath = 'auth/login';
	protected $username = 'name';
    

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            //'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return Users::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
    
    public function getLogout(){
	
	    Auth::logout();
	    
	    return redirect('auth/login');
    }
	
	
	/**
	 * 注册用户
	 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
	 */
//    public function getRegister(){
//
//    	return view('auth.register');
//    }
//
//	public function getLogin(){
//
//		return view('auth.login');
//	}
	
//	/**
//	 * 提交注册信息
//	 * @param Request $request
//	 *
//	 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
//	 */
//    public function postRegister(Request $request){
//
//    	$data = array();
//    	$data['name'] = $request->input('name');
//	    $data['email'] = $request->input('email');
//	    $data['password'] = $request->input('password');
//
//	    if($this->create($data)){
//
//	    	return redirect('auth/login');
//	    }else{
//
//	    	return redirect('auth/register');
//	    }
//    }
	
//	public function postLogin(Request $request){
//
//		$data = array();
//		$data['name'] = $request->input('name');
//		$data['password'] = $request->input('password');
//
//		if($this->validate($data)){
//
//			return redirect('admin/products');
//		}else{
//
//			return redirect('auth/login');
//		}
//	}
}
